using System;
using System.Data;
using System.Data.SqlClient;
using PHSRAG.Utility;
using BO = PHSRAG.Insight21.BusinessObjects;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
using GenerateKey = PHSRAG.Insight21.BusinessObjects.ModuleKey;

namespace PHSRAG.Insight21.Admin
{
	/// <summary>
	/// The object represents HRDepartments within Admin module. It has methods
	/// to load the department based on some criteria, and also methods to persist, 
	/// remove and retrieve itself from session.
	/// </summary>
	public class HRDepartments : BO.BusinessObject
	{
		#region Constants
		private const string HRDepartmentsTableName = "HRDepartments";
		private static string HRDepartmentsKey = GenerateKey.MakeKey("HRDepartmentsKey_D5F30071-B7B9-4d86-896A-E4D2A585DDR7",GenerateKey.Admin);
		private const string GetAdminHRDepartmentsSprocName = "GetAdminHRDepartments";
		#endregion

		#region Constructor
		/// <summary>
		/// Instantiates the data container.
		/// </summary>
		/// <param name="cachePolicy">Application's cache policy.</param>
		public HRDepartments(ICachePolicy cachePolicy) : base(cachePolicy)
		{
			DataContainer = new DataSet();
		}

		#endregion

		#region Class Properties
		/// <summary>
		/// Get the key to be used in all caching operations for this instance of the object.
		/// </summary>
		public static string CacheKey	{ get { return HRDepartmentsKey; } }
		#endregion

		#region Base Class Overrides
		/// <summary>
		/// Puts this instance to session.
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(HRDepartmentsKey, this);
		}

		/// <summary>
		/// Removes this instance from session.
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(HRDepartmentsKey);
		}

		/// <summary>
		/// Loads the data container with data from repository.
		/// </summary>
		/// <param name="connectionString">The connection string to the data source.</param>
		/// <param name="args">arguments to be passed to the stored procedure.</param>
		public override void Load(string connectionString, params object[] args)
		{
			DataAccess.LoadDataSet(DataContainer, HRDepartmentsTableName, connectionString,
				GetAdminHRDepartmentsSprocName,
				DataAccess.BuildSqlParameterArray(
				"@hrDepartmentCode", SqlDbType.VarChar, args[0],
				"@userName", SqlDbType.VarChar, args[1],
				"@lastName", SqlDbType.VarChar, args[2],
				"@firstName", SqlDbType.VarChar, args[3]));
		}
		#endregion
	}
}
